package com.ruoyi.project.lesson.lessonad.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.lesson.lessonad.domain.LessonAd;
import com.ruoyi.project.lesson.lessonad.service.ILessonAdService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 推广位置Controller
 * 
 * @author shixiangwen
 * @date 2020-12-22
 */
@Controller
@RequestMapping("/lesson/lessonad")
public class LessonAdController extends BaseController
{
    private String prefix = "lesson/lessonad";

    @Autowired
    private ILessonAdService lessonAdService;

    @RequiresPermissions("lesson:lessonad:view")
    @GetMapping()
    public String lessonad()
    {
        return prefix + "/lessonad";
    }

    /**
     * 查询推广位置列表
     */
    @RequiresPermissions("lesson:lessonad:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LessonAd lessonAd)
    {
        startPage();
        List<LessonAd> list = lessonAdService.selectLessonAdList(lessonAd);
        return getDataTable(list);
    }

    /**
     * 导出推广位置列表
     */
    @RequiresPermissions("lesson:lessonad:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LessonAd lessonAd)
    {
        List<LessonAd> list = lessonAdService.selectLessonAdList(lessonAd);
        ExcelUtil<LessonAd> util = new ExcelUtil<LessonAd>(LessonAd.class);
        return util.exportExcel(list, "lessonad");
    }

    /**
     * 新增推广位置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存推广位置
     */
    @RequiresPermissions("lesson:lessonad:add")
    @Log(title = "推广位置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LessonAd lessonAd)
    {
        return toAjax(lessonAdService.insertLessonAd(lessonAd));
    }

    /**
     * 修改推广位置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LessonAd lessonAd = lessonAdService.selectLessonAdById(id);
        mmap.put("lessonAd", lessonAd);
        return prefix + "/edit";
    }

    /**
     * 修改保存推广位置
     */
    @RequiresPermissions("lesson:lessonad:edit")
    @Log(title = "推广位置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LessonAd lessonAd)
    {
        return toAjax(lessonAdService.updateLessonAd(lessonAd));
    }

    /**
     * 删除推广位置
     */
    @RequiresPermissions("lesson:lessonad:remove")
    @Log(title = "推广位置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lessonAdService.deleteLessonAdByIds(ids));
    }
}
